package main
import (
	"io/ioutil"
	"os/exec"
	"fmt"
	"os"
	_ "flag"
	"strings"
)

func main(){
    file, _ := os.OpenFile("./tmp",os.O_RDWR|os.O_CREATE|os.O_TRUNC,0644)

    for _,v := range os.Args[1:]{
        if _, err := file.WriteString("file " + v + " \n" );err != nil {
            panic("write file error")
        }
    }
    file.Close()
    //var command = flag.String("c", "ffmpeg", "command name")
    //flag.Parse()
    //fmt.Println(*command)
    command :=  "ffmpeg -f concat -safe 0 -i tmp -movflags +faststart -c copy -y output.mp4"
    tmp:=strings.Split(command, " ")
    fmt.Println(tmp)
    cmd := exec.Command(tmp[0], tmp[1:]...)
    stdout, _ := cmd.StdoutPipe()
    stderr, _  := cmd.StderrPipe()
    cmd.Start()
    content, _ := ioutil.ReadAll(stdout)
    fmt.Println("FFMPEG--" + string(content))
    b, _ := ioutil.ReadAll(stderr)
    fmt.Println(string(b))
    cmd.Wait()
    os.Remove("./tmp")
}
